package com.xyht.sca_s.student_manage_system.modules.inform.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RepeatRequestCheck;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.inform.entity.SmsInform;
import com.xyht.sca_s.student_manage_system.modules.inform.entity.dto.SmsInformDetailAddDto;
import com.xyht.sca_s.student_manage_system.modules.inform.entity.dto.SmsInformDetailUpdateDto;
import com.xyht.sca_s.student_manage_system.modules.inform.entity.dto.SmsInformIdDto;
import com.xyht.sca_s.student_manage_system.modules.inform.service.SmsInformService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2022-12-04
 */
@RestController
@RequestMapping("/inform")
@SecretBody
public class SmsInformController {
    @Resource
    private JwtTokenUtil jwtTokenUtil;
    @Resource
    private SmsInformService smsInformService;

    @ApiModelProperty(value = "添加通告")
    @PostMapping("/teacher/add")
    public ResponseResult addInform(@RequestBody SmsInformDetailAddDto informDto, HttpServletRequest request){
        String issuerId = jwtTokenUtil.getUserIdByRequest(request);
        return smsInformService.addInform(informDto,issuerId);
    }

    @ApiModelProperty(value = "查询单个通告")
    @GetMapping("/id")
    public ResponseResult getInformDetail(HttpServletRequest request,@RequestParam(value = "id",required = false) String id ){
        String issuerId = jwtTokenUtil.getUserIdByRequest(request);
        return smsInformService.getInformById(id,issuerId);
    }

    @ApiModelProperty(value = "修改通告")
    @PostMapping("/teacher/update")
    public ResponseResult updateInformDetail(@RequestBody SmsInformDetailUpdateDto smsInformDetailUpdateDto,HttpServletRequest request){
        String issuerId = jwtTokenUtil.getUserIdByRequest(request);
        return smsInformService.updateInform(smsInformDetailUpdateDto,issuerId);
    }

    @ApiModelProperty(value = "删除通告")
    @PostMapping("/teacher/delete")
    public ResponseResult deleteInformById(@RequestBody SmsInform smsInform){
        return smsInformService.deleteInform(smsInform);
    }



    @ApiModelProperty(value = "学生端查看所有通知")
    @GetMapping("/student/all")
    public ResponseResult getAllInform(HttpServletRequest request,
                                       @RequestParam(value = "notificationType",required = false) String notificationType,
                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsInformService.getAllInform(userId,notificationType,pageSize,pageNum);
    }

    @ApiModelProperty(value = "后台查看所有通知")
    @GetMapping("/teacher/all")
    public ResponseResult getAllBlackInform(HttpServletRequest request,
                                            @RequestParam(value = "isBanner", required = false) Integer isBanner,
                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "type", required = false)String type,
                                            @RequestParam(value = "search", required = false)String search,
                                            @RequestParam(value = "notificationType", required = false)String notificationType,
                                            @RequestParam(value = "beginTime",required = false)String beginTime,
                                            @RequestParam(value = "endTime", required = false) String endTime,
                                            @RequestParam(value = "userId", required = false)String userId){
        String issuerId = jwtTokenUtil.getUserIdByRequest(request);
        return smsInformService.getAllBlackInform(issuerId,isBanner,pageSize,pageNum,type,search,notificationType,userId,beginTime,endTime);
    }

    @ApiModelProperty(value = "小程序轮播图")
    @GetMapping("/banner")
    public ResponseResult getBanner(){
        return smsInformService.getBanner();
    }


    @ApiModelProperty(value = "点赞功能")
    @PostMapping("/likes")
    @RepeatRequestCheck
    public ResponseResult likes(HttpServletRequest request,@RequestBody SmsInformIdDto informId){
        String likeUserId = jwtTokenUtil.getUserIdByRequest(request);
        return smsInformService.likes(likeUserId,informId);
    }


    @ApiModelProperty(value = "收藏功能")
    @PostMapping("/collect")
    @RepeatRequestCheck
    public ResponseResult collect(HttpServletRequest request,@RequestBody SmsInformIdDto informId){
        String collectUserId = jwtTokenUtil.getUserIdByRequest(request);
        return smsInformService.collect(collectUserId,informId);
    }

    @ApiModelProperty(value = "获取用户的班级")
    @GetMapping("/getClassInfo")
    public ResponseResult getClassInfo(HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsInformService.getClassInfo(userId);
    }


}

